package mrusanov.nation

import mrusanov.team.Club
import mrusanov.player.{ Player, Talent }
import util.Random
import mrusanov.player.psychology.PlayerPsychology
import java.util.{ Calendar, Date }
import mrusanov.team.Team

class ClubGenerator(startDate: Date) {
	def generateClubs(nation: Nation) {
		nation.clubs.foreach(c => {
			(0 until 10).foreach(i => {
				c.firstTeam.roster :+= generatePlayer(nation, c.firstTeam, junior = false)
				c.secondTeam.roster :+= generatePlayer(nation, c.secondTeam, junior = false)
				c.juniorTeam.roster :+= generatePlayer(nation, c.juniorTeam, junior = true)
			})
		})
	}

	// TODO remove this method with time
	private def generatePlayer(nation: Nation, team: Team, junior: Boolean): Player = {
		val talent = Talent.random
		val playerType = nation.randomPlayerType
		val age = if (junior) 14 + Random.nextInt(4) else 18 + Random.nextInt(16)
		val birthDate = Calendar.getInstance()
		birthDate.setTime(startDate)
		birthDate.add(Calendar.YEAR, -age)

		val result = Player(Random.nextFloat().toString, talent, birthDate.getTime, 0, nation, playerType)
		result.team = Some(team)
		result
	}
}
